Page({
    data: {
        express_no: "",
        express: "",
        customer_name: "",
        code: "",
        page_loading: !0,
        words: "",
        list: [],
        dialog: !1,
        id: "",
        value: 0,
        is_send: 0,
        order_refund_id: 0
    },
    codeInput: function(t) {
        this.setData({
            code: t.detail.value
        });
    },
    onLoad: function(t) {
        t.id > 0 && this.setData({
            id: t.id
        }), t.order_refund_id > 0 && this.setData({
            order_refund_id: t.order_refund_id
        }), this.getExpress(), t.is_send > 0 && this.setData({
            is_send: t.is_send
        });
    },
    getExpressNo: function() {
        var t = this, e = this;
      getApp().core.showLoading({
            title: "加载中"
        }), getApp().request({
            url: getApp().api.admin.order.print,
            data: {
                express: e.data.express,
                code: e.data.code,
                order_id: e.data.id
            },
            method: "get",
            success:function (e) {
              if (getApp().core.hideLoading(), 0 == e.code) {
                var a = e.data.data.Order;
                t.setData({
                  express_no: a.OrderCode
                });
              } else getApp().core.showToast({
                title: e.msg,
                icon:'none'
              });
            },
            flie: function () {
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              });
            }
        })
    },
    getList: function() {
        var t = this, e = this;
        getApp().request({
            url: getApp().api.admin.order.ex_detail,
            data: {
                order_id: e.data.id
            },
            method: "post",
            success:function(e) {
              getApp().core.hideLoading()
              if (0 == e.code) {
                var a = e.data.order;
                t.setData({
                  express: a.express,
                  express_no: a.express_no,
                  // customer_name: a.customer_name,
                  // code: a.code ? a.code : "",
                  words: a.words
                });
              } else getApp().core.showToast({
                title: e.data.msg,
                icon: 'none'
              });
            },
            flie: function(t) {
              getApp().core.showToast({
                title: t.msg,
                icon:'none'
              });
            }
        });
    },
    getCustomer: function() {
        var t = this;
        getApp().request({
            url: getApp().apiUrl.order.customer,
            method: "get"
        }).then(function(e) {
            if (getApp().iView.$Toast.hide(), 0 == e.data.code) {
                var a = e.data.data.customer_account;
                t.setData({
                    customer_name: a
                });
            } else getApp().iView.$Toast({
                content: e.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    bindChange: function(t) {
        var e = t.detail.value[0], a = this.data.list[e];
        this.setData({
            express: a
        });
    },
    toPick: function() {
        var t = this;
        this.setData({
            customer_name: ""
        }), t.data.list.forEach(function(e, a) {
            t.data.list[a].name == t.data.express && ("京东物流" == t.data.list[a].name && t.getCustomer(), 
            t.setData({
                value: a
            }));
        }), t.setData({
            dialog: !t.data.dialog
        });
    },
    areaEvent: function(t) {
        t.detail && this.setData({
            province: t.detail.province.name,
            city: t.detail.city.name,
            district: t.detail.district.name
        });
    },
    saveAddress: function(t) {
        var e = this, a = this;
        getApp().core.showLoading({
            content: "加载中"
        }), t.detail.value.express_no ? a.data.id > 0 ? getApp().request({
            url: getApp().api.admin.order.send,
            method: "POST",
            data: {
                // is_express: 1,
                order_id: a.data.id,
                express_no: t.detail.value.express_no,
                express: this.data.express,
                // code: this.data.code,
                // customer_name: t.detail.value.customer_name,
                words: t.detail.value.words
            },
            success:function (t) {
              getApp().core.hideLoading()
              0 == e.code ? getApp().core.showToast({
                title: "修改成功",
                icon: 'none'
              }) : getApp().core.showToast({
                title: t.msg,
                icon:'none'
              }), 0 == t.code && setTimeout(function () {
                getApp().core.navigateBack();
              }, 500);
            },
            flie: function() {

            }
        }).then(function(t) {
            
        }) : a.data.order_refund_id > 0 && getApp().request({
            url: getApp().apiUrl.app_admin.refund_handle,
            method: "POST",
            data: {
                is_express: 1,
                type: 2,
                is_agree: 1,
                order_refund_id: a.data.order_refund_id,
                express_no: t.detail.value.express_no,
                express: this.data.express,
                merchant_remark: t.detail.value.words
            }
        }).then(function(t) {
            getApp().iView.$Toast.hide(), getApp().iView.$Toast({
                content: t.data.msg
            }), 0 == t.data.code && setTimeout(function() {
                getApp().api.navigateBack();
            }, 500);
        }) : getApp().iView.$Toast({
            content: "快递单号不得为空",
            duration: 2,
            type: "warning"
        });
    },
    getExpress: function() {
        var t = this;
        getApp().core.showLoading({
            content: "加载中"
        }), getApp().request({
            url: getApp().api.admin.order.express,
            method: "get",
            success: function (e) {
              if (0 == e.code) {
                var a = e.data.list;
                t.setData({
                  list: a
                }), t.data.is_send > 0 && t.data.id > 0 ? t.getList() : (getApp().core.hideLoading(),
                  t.setData({
                    express: a[0]
                  }));
              } else getApp().core.showToast({
                title: e.msg,
                icon: 'none'
              });
            },
            flie: function (t) {
              getApp().core.showToast({
                title: t.msg
              });
            }
        });
    },
    onReady: function(t) {
        this.setData({
            page_loading: !1
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});